package com.ctshk.rpc.cms.mapper;

import com.ctshk.rpc.cms.dto.BranchOfficeDTO;
import com.ctshk.rpc.cms.entity.BranchOffice;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 * 分社表 Mapper 接口
 * </p>
 *
 * @author LiZhiming
 * @since 2021-04-23
 */
public interface BranchOfficeMapper extends BaseMapper<BranchOffice> {
    @Update("update t_branch_office set status = #{status} where id=#{id}")
    int updateStatusById(@Param("id")Long id, @Param("status")Integer status);

    @Select("select *,ROUND(6378.138*2*ASIN(SQRT(" +
            "POW(SIN((latitude*PI()/180-#{lat}*PI()/180)/2),2)+COS(latitude*PI()/180)*COS(#{lat}*PI()/180)*POW(SIN((longitude*PI()/180-#{lon}*PI()/180)/2),2)" +
            "))*1000) as meter from t_branch_office where is_deleted = #{isDeleted} and status = #{status} order by meter")
    List<BranchOfficeDTO> getBranchOffices(Double lat, Double lon, int isDeleted, int status);
}
